﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : 시스템
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd3012p
/// 파  일  명 : Crd3012p.aspx.cs
/// 설      명 : 결제카드변경
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2010-06-03 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web.UI;

using SMFramework.Data;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;
using Updms.Crd.Exe;


namespace Updms.Crd
{
	public partial class Crd3012p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Crd3012p";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";

		Global global = new Global();

		//검색
		protected string kw1 = "";	//카드코드
		protected string kw2 = "";	//카드사용일
		protected string kw3 = "";	//결제내용

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SetCardInfo();
				SetPaymntDtList(ddl_card_cd.SelectedValue);
				SetCardPaymntDt(kw2);
				SearchProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript

		private void SetClientScript()
		{
			//달력콘트롤 설정
			//ce_biz_dt.SelectedDate = DateTime.Now.AddDays(0);
		}

		#endregion

		#region SetInit, SetSearchParameter

		//초기값설정
		private void SetInit()
		{

		}

		//검색파라미터
		private void SetSearchParameter()
		{
			lbl_pk.Text = string.IsNullOrEmpty(Request.QueryString["seq"]) ? "" : Request.QueryString["seq"].ToString();
			kw1 = string.IsNullOrEmpty(Request.QueryString["card_cd"]) ? "" : Request.QueryString["card_cd"].ToString();
			kw2 = string.IsNullOrEmpty(Request.QueryString["biz_dt"]) ? "" : Request.QueryString["biz_dt"].ToString();
			kw3 = string.IsNullOrEmpty(Request.QueryString["contents"]) ? "" : Server.UrlDecode(Request.QueryString["contents"].ToString());
		}

		#endregion

		#region 디테일 Method (SetPaymntDtList, SetCardPaymntDt)

		//카드
		private void SetCardInfo()
		{
			DataSet lo_ds = new DataSet();
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();

			lo_ds.Merge(_Crd1010m_NT.GetCardInfoList("Y"));

			ddl_card_cd.Items.Clear();
			ddl_card_cd.DataSource = lo_ds;
			ddl_card_cd.DataMember = "UPDMS_CRD_INFO";
			ddl_card_cd.DataTextField = "Card_Nm";
			ddl_card_cd.DataValueField = "Card_Cd";
			ddl_card_cd.DataBind();
		}

		//결제예정일
		private void SetPaymntDtList(string ls_card_cd)
		{
			DataSet lo_ds = new DataSet();
			Crd1011m_NT _Crd1011m_NT = new Crd1011m_NT();

			lo_ds.Merge(_Crd1011m_NT.GetPaymntDtList(ls_card_cd));

			ddl_paymnt_dt.Items.Clear();
			ddl_paymnt_dt.DataSource = lo_ds;
			ddl_paymnt_dt.DataMember = "UPDMS_CRD_PAYMNT_DT";
			ddl_paymnt_dt.DataTextField = "Text";
			ddl_paymnt_dt.DataValueField = "Value";
			ddl_paymnt_dt.DataBind();
		}

		//결제일별 결제예정일 지정
		private void SetCardPaymntDt(string ls_biz_dt)
		{
			string ls_paymnt_dt = "";
			DataPack lo_dp = new DataPack();

			Crd1011m_NT _Crd1011m_NT = new Crd1011m_NT();

			lo_dp.AddProperty("ls_card_cd", typeof(string), ddl_card_cd.SelectedValue);
			lo_dp.AddProperty("ls_biz_dt", typeof(string), ls_biz_dt);

			ls_paymnt_dt = _Crd1011m_NT.GetPaymntDtByBizDt(lo_dp);
			ddl_paymnt_dt.SelectedValue = ls_paymnt_dt;
		}

		//카드 변경시
		protected void ddl_card_cd_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetPaymntDtList(ddl_card_cd.SelectedValue);
			SetCardPaymntDt(txt_biz_dt.Text.Trim());
		}

		#endregion

		#region CRUD (SelectProcess, UpdateProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			ddl_card_cd.SelectedValue = kw1;
			txt_biz_dt.Text = kw2;
			SetCardPaymntDt(kw2);
			lbl_search_keyword.Text = kw3;
		}

		//수정
		private void UpdateProcess()
		{
			using (Crd1012m_RT _Crd1012m_RT = new Crd1012m_RT())
			{
				int li_return = _Crd1012m_RT.ChangeCardCd(SetValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_010" : "MSG_ERR_110";	//변경되었습니다:변경할 수 없습니다
				string ls_msg_tp = (li_return > 0) ? "ICR" : "AC";
				
				CallMsgBoxInAjax(ls_msg_id, null ,ls_msg_tp);
			}
		}

		//검색
		private void SearchProcess()
		{
			SetSearchParameter();
			SelectProcess();
		}

		#endregion

		#region SetValue

		//SetValue
		private DataPack SetValue()
		{
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("li_seq", typeof(string), lbl_pk.Text);
			lo_dp.AddProperty("ls_card_cd", typeof(string), ddl_card_cd.SelectedValue);			
			lo_dp.AddProperty("ls_biz_dt", typeof(string), txt_biz_dt.Text);
			lo_dp.AddProperty("ls_paymnt_dt", typeof(string), ddl_paymnt_dt.SelectedValue);
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);

			return lo_dp;
		}

		#endregion

		#region Page_PreRender

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
		}

		#endregion		

		#region 버튼이벤트

		//저장
		protected void ibtn_save_Click(object sender, EventArgs e)
		{
			UpdateProcess();
		}

		//결제예정일 계산
		protected void lbtn_paymnt_dt_Click(object sender, EventArgs e)
		{
			if (ddl_paymnt_dt.Items.Count > 0)
			{
				SetCardPaymntDt(txt_biz_dt.Text);
			}
			else
			{
				CallMsgBoxInAjax("MSG_ERR_142");	//지정된 결제일이 없습니다.\n'카드결제일관리'에서 추가해 주세요
			}
		}

		#endregion


	}
}
